/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeNodes(ListNode* head)
    {
        int sum = 0;
        ListNode* cur = head->next;
        ListNode* ans = new ListNode;
        ListNode* pcur = ans;
        while (cur)
        {
            if (cur->val == 0)
            {
                ListNode* tmp = new ListNode(sum);
                pcur->next = tmp;
                pcur = pcur->next;
                sum = 0;
            }
            else sum += cur->val;
            cur = cur->next;
        }
        return ans->next;
    }
};